package com.example.demo.leetcode.top100;

/**
 * ******************************************************
 *
 * @author liugh9
 * @version 1.0
 * @classname _78跳跃游戏
 * @description
 * @date 2023/06/27 17:34
 * <p>
 * ******************************************************
 */
public class _78跳跃游戏 {

    public boolean canJump(int[] nums) {
        int length = nums.length;
        boolean[] dp = new boolean[length];
        dp[0] = true;
        for (int i = 1; i <= nums[0] && i < length; i++) {
            dp[i] = true;
        }
        for (int i = 1; i < length; i++) {
            if (dp[length-1]) {
                return true;
            }
            if (dp[i]) {
                for (int j = 1; j <= nums[i] && (i + j) < length; j++) {
                    dp[i + j] = true;
                }
            }
        }

        return dp[length - 1];
    }
}
